package com.activity;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import com.adapter.AdapterListView;
import com.bean.ConteudoBean;
import com.connection.DatabaseConnection;
import com.dao.ConteudoDao;

import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ConteudoActivity extends Activity {
	
	ListView listCont;
	Bundle param;
	
	private ListView listView;
	private AdapterListView adapterListView;
	private List<ConteudoBean> conteudos;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.listconteudo);
		
		DatabaseConnection data = new DatabaseConnection(
				getApplicationContext());
		SQLiteDatabase escola = data.getWritableDatabase();
		
		//pega a referencia do listView
		listCont = (ListView)findViewById(R.id.listConteudo);
		
		conteudos = new ArrayList<ConteudoBean>();
		
		Intent it = getIntent();
		if(it != null){
			param = it.getExtras();
			if(param != null){
				try {
					conteudos = new ConteudoDao().getAll(escola, param.getInt("id_unidade"), param.getInt("id_disciplina"), param.getInt("id_turma"), param.getInt("id_bimestre"));
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}
		}
		
		List<String> StrConteudos = new ArrayList<String>();
		
		for(int i=0; i<conteudos.size(); i++){
			StrConteudos.add(conteudos.get(i).getConteudo());
		}
		
		
		
		adapterListView = new AdapterListView(this, conteudos);
		listCont.setAdapter(adapterListView);
		
		escola.close();
		
	}
	
	    public void abre_novoconteudo(View v) {
	    	Intent i_novo_cont = new Intent(getApplicationContext(), NovoConteudoActivity.class);
	    	i_novo_cont.putExtras(param);
			startActivity(i_novo_cont);
			
		}

}